package com.wm.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wm.commonutils.R;
import com.wm.eduService.entity.EduCourse;
import com.wm.eduService.entity.EduTeacher;
import com.wm.eduService.service.EduCourseService;
import com.wm.eduService.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: sshdg
 * @Date: 2020/10/7 14:45
 */
@RestController
@RequestMapping("/eduService/teacherFront")
//@CrossOrigin
@Api(tags = "讲师前台接口")
public class TeacherFrontController {

    @Autowired
    EduCourseService courseService;
    @Autowired
    EduTeacherService teacherService;

    @ApiOperation("讲师C端分页查询")
    @GetMapping("/getTeacherInfoList/{page}/{size}")
    public R getTeacherFrontList(@PathVariable long page , @PathVariable long size){

        Page<EduTeacher> teacherPage = new Page<>(page,size);
        teacherPage = teacherService.getTeacherFrontList(teacherPage);

        boolean hasNext = teacherPage.hasNext();
        boolean hasPrevious = teacherPage.hasPrevious();

        return R.ok().data("page",teacherPage)
                .data("hasNext" ,hasNext)
                .data("hasPrevious" ,hasPrevious);
    }

    @ApiOperation("讲师详情的功能")
    @GetMapping("/getTeacherFrontInfo/{teacherId}")
    public R getTeacherFront(@PathVariable String teacherId){

        //1.根据讲师id查询讲师的基本信息
        EduTeacher teacher = teacherService.getById(teacherId);

        //2.根据讲师查询所讲课程
        LambdaQueryWrapper<EduCourse> courseQuery = new LambdaQueryWrapper<>();
        courseQuery.eq(EduCourse::getTeacherId,teacherId);
        List<EduCourse> courseList = courseService.list(courseQuery);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
